/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.ventas;

import dp1.titandevelop.titano.view.sec.*;
import dp1.titandevelop.titano.service.AuditoriaService;
import dp1.titandevelop.titano.view.CambiarPassword;
import dp1.titandevelop.titano.view.LoginT;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author christianjuarez
 */
public class ModulosT_VEN extends javax.swing.JFrame {

    public static ModulosT_VEN_AD menuItemDist = null;
    public static ModulosT_VEN_ASP menuItemSPed = null;
    public static ModulosT_VEN_AV menuItemV = null;
    public static ModulosT_VEN_PProduccion menuItemPP = null;
    public static ModulosT_VEN_ANC menuItemNC = null;
    public static ModulosT_VEN_ReporteVentas ventanaReporte = null;
    private BufferedImage imgFondo;
    
    public ModulosT_VEN() {
        initComponents();

        this.setLocationRelativeTo(null);
        this.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        try {
            //this.getClass().getResource("/img/fondo.png").toURI();
            this.imgFondo = ImageIO.read(getClass().getResourceAsStream("/img/fondoTitanBright.png"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        escritorioVentas = new javax.swing.JDesktopPane() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(imgFondo, 0, 0, this);
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(imgFondo.getWidth(), imgFondo.getHeight());
            }

            public void paint(Graphics g, JComponent c) {
                //super.paintComponent(g);
                g.drawImage(imgFondo, 0, 0, c.getWidth(), c.getHeight(), null);
            }
        };
        jPanel2 = new javax.swing.JPanel();
        lblUsuario = new javax.swing.JLabel();
        lblUsuarioLogeado = new javax.swing.JLabel();
        lblCorreo = new javax.swing.JLabel();
        lblCorreoLogeado = new javax.swing.JLabel();
        btnCambiarPW = new javax.swing.JButton();
        lblPerfil = new javax.swing.JLabel();
        lblPerfilLogeado = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuAdm = new javax.swing.JMenu();
        menuItemSolPed = new javax.swing.JMenuItem();
        menuItemDistri = new javax.swing.JMenuItem();
        menuItemVenta = new javax.swing.JMenuItem();
        menuItemPlan = new javax.swing.JMenuItem();
        menuNotaCredito = new javax.swing.JMenuItem();
        menuRepo = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setTitle("Módulo Ventas");

        escritorioVentas.setPreferredSize(null);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblUsuario.setText("Usuario:");

        lblUsuarioLogeado.setText(LoginT.empleadoLogin.getNombres()+" "+LoginT.empleadoLogin.getApellidop()+" "+LoginT.empleadoLogin.getApellidom()+" "+"("+LoginT.userLogin.getUsuario()+")");

        lblCorreo.setText("Correo:");

        lblCorreoLogeado.setText(LoginT.empleadoLogin.getEmail());

        btnCambiarPW.setText("Cambiar Password");
        btnCambiarPW.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        btnCambiarPW.setPreferredSize(new java.awt.Dimension(121, 20));
        btnCambiarPW.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCambiarPWActionPerformed(evt);
            }
        });

        lblPerfil.setText("Perfil:");

        lblPerfilLogeado.setText(LoginT.perfilLogin.getDescripcion());

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/usuario.png"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/perfilesactivos.png"))); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/correo.png"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblUsuarioLogeado)
                .addGap(27, 27, 27)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCorreo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCorreoLogeado)
                .addGap(32, 32, 32)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPerfil)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPerfilLogeado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnCambiarPW, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUsuario)
                    .addComponent(lblUsuarioLogeado)
                    .addComponent(lblCorreo)
                    .addComponent(lblCorreoLogeado)
                    .addComponent(btnCambiarPW, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPerfil)
                    .addComponent(lblPerfilLogeado)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)))
        );

        menuAdm.setText("Administrar");

        menuItemSolPed.setText("Solicitud Pedido");
        menuItemSolPed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSolPedActionPerformed(evt);
            }
        });
        menuAdm.add(menuItemSolPed);

        menuItemDistri.setText("Distribuidor");
        menuItemDistri.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemDistriActionPerformed(evt);
            }
        });
        menuAdm.add(menuItemDistri);

        menuItemVenta.setText("Venta");
        menuItemVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemVentaActionPerformed(evt);
            }
        });
        menuAdm.add(menuItemVenta);

        menuItemPlan.setText("Plan de Produccion");
        menuItemPlan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemPlanActionPerformed(evt);
            }
        });
        menuAdm.add(menuItemPlan);

        menuNotaCredito.setText("Nota de Crédito");
        menuNotaCredito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNotaCreditoActionPerformed(evt);
            }
        });
        menuAdm.add(menuNotaCredito);

        jMenuBar1.add(menuAdm);

        menuRepo.setText("Reportes");

        jMenuItem1.setText("Ventas");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuRepo.add(jMenuItem1);

        jMenuBar1.add(menuRepo);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(escritorioVentas, javax.swing.GroupLayout.DEFAULT_SIZE, 829, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(escritorioVentas, javax.swing.GroupLayout.DEFAULT_SIZE, 830, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCambiarPWActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCambiarPWActionPerformed

        CambiarPassword chngpw = new CambiarPassword(new javax.swing.JFrame(), true);
        chngpw.setLocationRelativeTo(null);
        chngpw.setVisible(true);
    }//GEN-LAST:event_btnCambiarPWActionPerformed

    private void menuItemSolPedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSolPedActionPerformed
        // Solicitud de pedido  ID 25

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (25 == (Integer) LoginT.idspermisosxperfil.get(i)) {

                menuItemSPed = new ModulosT_VEN_ASP();
                this.escritorioVentas.add(menuItemSPed);

                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuItemSPed.getSize();
                menuItemSPed.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);
                menuItemSPed.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioVentas, "No puedes proceder, al parecer careces de permisos.",
                "No posee permisos",
                JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_menuItemSolPedActionPerformed

    private void menuItemDistriActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemDistriActionPerformed
        // Distribuidor  ID 26

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (26 == (Integer) LoginT.idspermisosxperfil.get(i)) {

                menuItemDist = new ModulosT_VEN_AD();
                this.escritorioVentas.add(menuItemDist);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuItemDist.getSize();
                menuItemDist.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);

                menuItemDist.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioVentas, "No puedes proceder, al parecer careces de permisos.",
                "No posee permisos",
                JOptionPane.WARNING_MESSAGE);
        }

    }//GEN-LAST:event_menuItemDistriActionPerformed

    private void menuItemVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemVentaActionPerformed
        // Distribuidor  ID 27

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (27 == (Integer) LoginT.idspermisosxperfil.get(i)) {
                menuItemV = new ModulosT_VEN_AV();
                this.escritorioVentas.add(menuItemV);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuItemV.getSize();
                menuItemV.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);

                menuItemV.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioVentas, "No puedes proceder, al parecer careces de permisos.",
                "No posee permisos",
                JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_menuItemVentaActionPerformed

    private void menuItemPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemPlanActionPerformed
        // Plan de Producción  ID 28

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (28 == (Integer) LoginT.idspermisosxperfil.get(i)) {

                menuItemPP = new ModulosT_VEN_PProduccion();
                this.escritorioVentas.add(menuItemPP);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuItemPP.getSize();
                menuItemPP.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);

                menuItemPP.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioVentas, "No puedes proceder, al parecer careces de permisos.",
                "No posee permisos",
                JOptionPane.WARNING_MESSAGE);
        }

    }//GEN-LAST:event_menuItemPlanActionPerformed

    private void menuNotaCreditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNotaCreditoActionPerformed
        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (28 == (Integer) LoginT.idspermisosxperfil.get(i)) {

                menuItemNC = new ModulosT_VEN_ANC();
                this.escritorioVentas.add(menuItemNC);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuItemNC.getSize();
                menuItemNC.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);

                menuItemNC.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioVentas, "No puedes proceder, al parecer careces de permisos.",
                "No posee permisos",
                JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_menuNotaCreditoActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        ventanaReporte= new ModulosT_VEN_ReporteVentas();
        this.escritorioVentas.add(ventanaReporte);
        Dimension desktopSize = this.getSize();
        Dimension jInternalFrameSize = ventanaReporte.getSize();
        ventanaReporte.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
            (desktopSize.height - jInternalFrameSize.height) / 4);
        ventanaReporte.show();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModulosT_SEG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModulosT_SEG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModulosT_SEG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModulosT_SEG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModulosT_SEG().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCambiarPW;
    private javax.swing.JDesktopPane escritorioVentas;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblCorreo;
    private javax.swing.JLabel lblCorreoLogeado;
    private javax.swing.JLabel lblPerfil;
    private javax.swing.JLabel lblPerfilLogeado;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JLabel lblUsuarioLogeado;
    private javax.swing.JMenu menuAdm;
    private javax.swing.JMenuItem menuItemDistri;
    private javax.swing.JMenuItem menuItemPlan;
    private javax.swing.JMenuItem menuItemSolPed;
    private javax.swing.JMenuItem menuItemVenta;
    private javax.swing.JMenuItem menuNotaCredito;
    private javax.swing.JMenu menuRepo;
    // End of variables declaration//GEN-END:variables
}
